%% Data:
fileName = {'data_45deg.mat', 'data_30deg.mat', ...
    'data_15deg.mat', 'data_5deg.mat', ...
    'data_-45deg.mat', 'data_-30deg.mat', ...
    'data_-15deg.mat', 'data_-5deg.mat' };

% training:
trainingData = [];
for i = 1:length(fileName)
    currentData = [];
    load(fileName{i});
    currentData = [out.state_data, ...
        out.control_input_data];
    trainingData = [trainingData; currentData];
end


%% Setup: (sequence to one)
numInput = 1; % sequence 4x1 
numResponses = 1; % one 1
 
% LSTM:
numHiddenUnits = 100;
layers = [ ...
    sequenceInputLayer(numInput, Normalization="zscore")
    lstmLayer(numHiddenUnits, OutputMode="last")
    fullyConnectedLayer(numResponses)
    regressionLayer];

options = trainingOptions("adam", ...
    MaxEpochs=2000, ...
    ValidationData= ...
    {num2cell(trainingData(:,1:4),2) ...
    trainingData(:,5)}, ...
    OutputNetwork="best-validation-loss", ...
    InitialLearnRate=0.001, ...
    SequenceLength="shortest", ...
    Plots="training-progress", ...
    Verbose= false);

policy = trainNetwork(num2cell(trainingData(:,1:4),2),...
    trainingData(:,5), layers, options);

